#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(s) s.begin(), s.end()
const int MOD = 998244353;

void solve() {
	int n, m, L, V; cin >> n >> m >> L >> V;
	vector<int> d(n + 1), v(n + 1), a(n + 1);
	vector<int> p(m + 1);
	for (int i = 1; i <= n; i++) cin >> d[i] >> v[i] >> a[i];
	for (int i = 1; i <= m; i++) cin >> p[i];
	int ans = 0;
	vector<int> r;
	vector<pair<int, int>> l;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 0) {
			if (v[i] <= V) continue;
			auto it = lower_bound(p.begin() + 1, p.end(), d[i]);
			if (it == p.end()) continue;
			ans++;
			r.push_back(it - p.begin());
		} else if (a[i] > 0) {
			int lim = 0;
			if (v[i] > V) lim = d[i];
			else lim = (V * V - v[i] * v[i]) / (2 * a[i]) + d[i] + 1;
			auto it = lower_bound(p.begin() + 1, p.end(), lim);
			if (it == p.end()) continue;
			ans++;
			r.push_back(it - p.begin());
		} else {
			if (v[i] <= V) continue;
			int lim = (v[i] * v[i] - V * V - 1) / (-2 * a[i]) + d[i];
			auto it = upper_bound(p.begin() + 1, p.end(), lim);
			if (it == p.begin()) continue;
			it--;
			auto it2 = lower_bound(p.begin() + 1, p.end(), d[i]);
			if (it2 == p.end() || it2 - it > 0) continue;
			ans++;
			l.push_back({it2 - p.begin(), it - p.begin()});
		}
	}
	int cnt = 0;
	sort(all(l), [&](auto x, auto y) {
		return x.second < y.second;
	});
	int cur = 0;
	vector<int> pl(m + 2), pr(m + 2);
	for (auto x : l) {
		if (cur < x.first) {
			cnt++;
			cur = x.second;
		}
		pl[x.second] = cnt;
	}
	for (int i = 1; i <= m; i++) {
		if (pl[i] == 0) pl[i] = pl[i - 1];
	}
	cur = cnt = 0;
	sort(all(l), [&](auto x, auto y) {
		return x.first > y.first;
	});
	for (auto x : l) {
		if (cur > x.second) {
			cnt++;
			cur = x.first;
		}
		pr[x.first] = cnt;
	}
	for (int i = m; i >= 0; i--) {
		if (pr[i] == 0) pr[i] = pr[i + 1];
	}
	if (r.empty()) {
		cout << ans << ' ' << m - pl[m] << '\n';
		return;
	}
	int oans = m;
	int R = *max_element(all(r));
	for (int i = R; i <= m; i++) {
		oans = min(oans, pl[i - 1] + 1 + pr[i + 1]);
	}
	cout << ans << ' ' << m - oans << '\n';
	return;
}

int main() {
	auto start = chrono::steady_clock::now();
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	auto end = chrono::steady_clock::now();
	cerr << "time: " << chrono::duration<double, milli>(end - start).count() << "ms" << endl;
}